var t = require("../../@babel/runtime/helpers/toConsumableArray"),
  a = require("../../@babel/runtime/helpers/createForOfIteratorHelper"),
  e = require("../../@babel/runtime/helpers/regeneratorRuntime"),
  i = require("../../@babel/runtime/helpers/asyncToGenerator"),
  s = require("../../utils/http.js"),
  r = require("../../utils/api.js"),
  d = require("../../utils/util.js"),
  o = require("../../utils/md5.js"),
  n = require("../../utils/language/switchLanguage.js"),
  u = require("../../utils/base64.js").weBtoa;
Page({
  data: {
    currentTabs: 1,
    languageType: "",
    dateList: [],
    timeInterval: [],
    currentdate: 0,
    num: 0,
    isShow: !1,
    isInstructions: !1,
    Ticketlist: [],
    touristList: [],
    name: "",
    IdCard: "",
    currentIdx: null,
    totalPrice: 0,
    date: "",
    showDate: "",
    count: 5,
    is_show: !1,
    isShowpayMent: !1,
    ConfirmPhone: "",
    ConcatList: [],
    ticketArray: ["身份证"],
    eticketArray: ["ID Card"],
    arrayList: [
      { name: "身份证", type: 0 },
      { name: "港澳居民来往内地通行证", type: 1 },
      { name: "台湾居民来往大陆通行证", type: 2 },
      { name: "护照", type: 4 },
      { name: "外国人永久居留证", type: 5 },
    ],
    array: [
      "身份证",
      "港澳居民来往内地通行证",
      "台湾居民来往大陆通行证",
      "护照",
      "外国人永久居留证",
    ],
    eArrayList: [
      { name: "ID Card", type: 0 },
      { name: "HK/Macau Mainland Travel Permit", type: 1 },
      { name: "Taiwan Mainland Travel Permit", type: 2 },
      { name: "Passport", type: 4 },
      { name: "Permanent Residence Permit for Foreigners", type: 5 },
    ],
    eArray: [
      "ID Card",
      "HK/Macau Mainland Travel Permit",
      "Taiwan Mainland Travel Permit",
      "Passport",
      "Permanent Residence Permit",
    ],
    CardTypeIdx: 0,
    CardType: null,
    productNoIdx: 0,
    isCandidate: "",
    payMent: "wxSmallPay",
    singleBookingLimit: "",
    currentTime: null,
    isShowCandidate: !1,
    isAgreeCandidate: 0,
    ticketReleaseTime: "20:00:00",
    isSelect: !1,
    userNum: 1,
    userList: [],
    ticketTypeList: [],
    isEditUser: !1,
    currentuserIdx: null,
    editType: "Group",
    isEditUserList: [],
    isAdultCount: 0,
    isChildCount: 0,
    codeValue: null,
    imgUrl: "",
    captchaType: "",
  },
  onLoad: function () {
    this.getUniversalTicketConfig(),
      this.getTicketConfig(),
      this.initLanguage(),
      wx.stopPullDownRefresh(),
      r.turingSDKInit(wx.getStorageSync("openId"));
  },
  changeTab: function (t) {
    var a = t.currentTarget.dataset.index;
    this.setData({ currentTabs: a - 0, productNoIdx: 0 }),
      this.getProductList();
  },
  _getNormalCodeImage: function () {
    var t = this;
    return i(
      e().mark(function a() {
        return e().wrap(function (a) {
          for (;;)
            switch ((a.prev = a.next)) {
              case 0:
                s.getNormalCodeImage().then(function (a) {
                  for (
                    var e = "",
                      i = new Uint8Array(a.data),
                      s = i.byteLength,
                      r = 0;
                    r < s;
                    r++
                  )
                    e += String.fromCharCode(i[r]);
                  var d = "data:image/png;base64,".concat(u(e));
                  t.setData({ imgUrl: d });
                });
              case 1:
              case "end":
                return a.stop();
            }
        }, a);
      }),
    )();
  },
  initLanguage: function () {
    var t = n.languageVersion(wx.getStorageSync("language"));
    this.setData({ _t: t, languageType: wx.getStorageSync("language") }),
      wx.setNavigationBarTitle({ title: t["个人预约"] });
  },
  Back: function () {
    2 == this.data.Ticketlist[this.data.productNoIdx].ticketClassify
      ? this.setData({
          isSelect: !1,
          userList: [],
          name: "",
          IdCard: "",
          currentIdx: null,
          isEditUser: !1,
        })
      : this.setData({ isSelect: !1, userList: [] });
  },
  nextStep: function () {
    if (2 !== this.data.Ticketlist[this.data.productNoIdx].ticketClassify)
      this.setData({
        userNum: 1,
        isSelect: !0,
        CardTypeIdx: 0,
        CardType: null,
      });
    else {
      var t =
        this.data.Ticketlist[this.data.productNoIdx].childrenNum +
        this.data.Ticketlist[this.data.productNoIdx].adultsNum;
      this.setData({
        userNum: t,
        isAdultCount: this.data.Ticketlist[this.data.productNoIdx].adultsNum,
        isChildCount: this.data.Ticketlist[this.data.productNoIdx].childrenNum,
        isSelect: !0,
        CardTypeIdx: "0",
        CardType: "0",
      });
    }
  },
  getUniversalTicketConfig: function () {
    var t = this;
    s.getUniversalTicketConfig().then(function (a) {
      console.log(a.data, "退改规则.data.");
      var e =
        0 == t.data.languageType ? a.data.refundNotes : a.data.refundNotesEn;
      t.setData({
        notice: a.data.notice,
        isCandidate: a.data.isCandidate,
        singleBookingLimit: a.data.singleBookingLimit,
        refundNotes: e,
        ticketReleaseTime: a.data.ticketReleaseTime,
      });
    });
  },
  getProductList: function () {
    var t = this;
    wx.showLoading({ title: this.data._t["加载中"] });
    var e = {
      orderType: 0,
      sourceType: 1,
      playDay: this.data.date,
      ticketType: this.data.currentTabs,
    };
    s.getProductList(e)
      .then(function (e) {
        var i,
          s = e.data,
          r = a(s);
        try {
          for (r.s(); !(i = r.n()).done; ) {
            i.value.number = 0;
          }
        } catch (t) {
          r.e(t);
        } finally {
          r.f();
        }
        t.setData({ Ticketlist: s }), wx.hideLoading();
      })
      .catch(function (t) {
        wx.hideLoading();
      });
  },
  codeValueChange: function (t) {
    var a = t.detail.value;
    console.log(555), this.setData({ codeValue: a });
  },
  getTicketConfig: function () {
    var t = this;
    s.getTicketConfig({ sourceType: 1 }).then(function (a) {
      for (var e = a.data.listBuyDays, i = 0; i < e.length; i++)
        "" != t.data.date ||
          e[i].reception ||
          e[i].stop ||
          e[i].stopEntering ||
          t.setData({ date: e[i].day, currentdate: i }),
          (e[i].year = e[i].day.substring(0, 5)),
          (e[i].week = e[i].week.substring(0, 3)),
          (e[i].day = e[i].day.substring(5, 10));
      t.setData({
        dateList: e,
        TicketConfig: a.data,
        captchaType: a.data.captchaType,
      }),
        t.getTimeSlotsLimit(),
        t.getProductList();
    });
  },
  getTimeSlotsLimit: function () {
    var t = this,
      a = { playDay: this.data.date, orderType: 0, sourceType: 1 };
    s.getTimeSlotsLimit(a).then(function (a) {
      t.setData({ timeInterval: a.data });
    });
  },
  onShow: function () {
    setTimeout(function () {}, 1500), this._getNormalCodeImage();
  },
  choosePeople: function (t) {
    var a = t.target.dataset.idx,
      e = this.data.ConcatList,
      i = this.data.arrayList.findIndex(function (t) {
        return (t.type == e[a].customerIdCardType) == 0
          ? "0"
          : e[a].customerIdCardType;
      });
    this.setData({
      concat_idx: a,
      name: e[a].customerName,
      IdCard: e[a].customerIdCard,
      CardTypeIdx: i,
    });
  },
  getConcatList: function () {
    var t = this;
    s.getConcatList().then(function (a) {
      t.setData({ ConcatList: a.data });
    });
  },
  realNameAuth: function (t, a, e) {
    s.realNameAuth(t, a).then(function (t) {
      if (void 0 !== e) {
        var a = { data: t.data, msg: t.msg };
        e(a);
      }
    });
  },
  ConfirmPament: function () {
    for (var a = [], e = this.data.ticketTypeList, i = 0; i < e.length; i++)
      for (var s = e[i].groupList, d = 0; d < s.length; d++) a.push(s[d]);
    (a = [].concat(t(a), t(this.data.touristList))),
      "" != this.data.date
        ? "" != this.data.currentTime && null != this.data.currentTime
          ? 0 != a
            ? "" != this.data.ConfirmPhone
              ? r.isMobile(this.data.ConfirmPhone)
                ? (this._getNormalCodeImage(),
                  "" != this.data.payMent
                    ? this.setData({ is_show: !0, codeValue: null })
                    : r.showMsg(this.data._t["请选择支付方式"]))
                : r.showMsg(this.data._t["手机号码格式有误"])
              : r.showMsg(this.data._t["请输入联系电话"])
            : r.showMsg(this.data._t["请先填写购票信息"])
          : r.showMsg(this.data._t["请选择参观时段"])
        : r.showMsg(this.data._t["请选择参观日期"]);
  },
  subForm: r.throttle(function () {
    console.log(1 == this.data.captchaType, !this.data.codeValue, "codeValue"),
      1 != this.data.captchaType || this.data.codeValue
        ? (this.CreateOrder(), this.setData({ is_show: !1 }))
        : r.showMsg(this.data._t["验证码不能为空"]);
  }),
  CreateOrder: function () {
    for (
      var e = this, i = [], d = this.data.ticketTypeList, n = 0;
      n < d.length;
      n++
    )
      for (var u = d[n].groupList, c = 0; c < u.length; c++) i.push(u[c]);
    if (((i = [].concat(t(i), t(this.data.touristList))), "" != this.data.date))
      if ("" != this.data.currentTime && null != this.data.currentTime)
        if (0 != i)
          if ("" != this.data.ConfirmPhone)
            if (r.isMobile(this.data.ConfirmPhone))
              if ("" != this.data.payMent) {
                wx.showLoading({ title: "", mask: !0 });
                var h,
                  l = this.data.date,
                  p = this.data.touristList,
                  m = {},
                  g = [],
                  I = a(p);
                try {
                  for (I.s(); !(h = I.n()).done; ) {
                    var f = h.value;
                    null != m[f.productNo]
                      ? (m[f.productNo].museumOrderUsers.push({
                          customerName: f.customerName,
                          customerIdCard: f.customerIdCard,
                          customerIdCardType: f.customerIdCardType,
                        }),
                        (m[f.productNo].orderQuantity =
                          m[f.productNo].orderQuantity + 1))
                      : (m[f.productNo] = {
                          museumOrderUsers: [
                            {
                              customerName: f.customerName,
                              customerIdCard: f.customerIdCard,
                              customerIdCardType: f.customerIdCardType,
                            },
                          ],
                          productNo: f.productNo,
                          playDay: l,
                          orderQuantity: 1,
                          timeSlotId:
                            this.data.timeInterval[this.data.currentTime].id,
                        });
                  }
                } catch (t) {
                  I.e(t);
                } finally {
                  I.f();
                }
                var y = d.map(function (t) {
                  return {
                    museumOrderUsers: t.groupList.map(function (t) {
                      return {
                        customerIdCard: t.customerIdCard,
                        customerIdCardType: t.customerIdCardType,
                        customerName: t.customerName,
                      };
                    }),
                    orderQuantity: t.nums,
                    playDay: l,
                    productNo: t.productNo,
                    timeSlotId: e.data.timeInterval[e.data.currentTime].id,
                  };
                });
                for (var T in m) g.push(m[T]);
                g = [].concat(t(g), t(y));
                var C = wx.getStorageSync("deviceToken"),
                  x = {
                    data: JSON.stringify(g),
                    orderType: 0,
                    sourceType: 1,
                    payType: 4,
                    tradeType: this.data.payMent,
                    payConfigType: 4,
                    isCandidate: this.data.isAgreeCandidate,
                    contactNumber: this.data.ConfirmPhone,
                    deviceId: C,
                  };
                1 == this.data.captchaType &&
                  (x.captchaInfo = {
                    captchaType: 3,
                    normalCode: { codeValue: this.data.codeValue },
                  });
                var v = r.encryptBASE64(JSON.stringify(x)),
                  L = {
                    sign: r.autograph(v),
                    signData: v,
                    openId: requireMiniProgram().getOpenId(),
                    unionId: wx.getStorageSync("uid"),
                    createTime: new Date().getTime(),
                    contactNumber: o.hex_md5(this.data.ConfirmPhone),
                    timeSlot:
                      this.data.timeInterval[this.data.currentTime].startTime +
                      "~" +
                      this.data.timeInterval[this.data.currentTime].endTime,
                    deviceId: C,
                    sourceType: 1,
                    ticketReleaseTime: this.data.ticketReleaseTime,
                  };
                s.CreateOrder(L)
                  .then(function (t) {
                    if (
                      (e.setData({
                        touristList: [],
                        ConfirmPhone: "",
                        totalPrice: 0,
                        date: "",
                        showDate: "",
                        currentdate: null,
                        currentTime: null,
                        ticketTypeList: [],
                      }),
                      wx.hideLoading(),
                      1 != t.orderStatus && 12 != t.orderStatus)
                    )
                      if (0 == t.orderStatus && "wxSmallPay" == e.data.payMent)
                        e.wechatPay(t.data);
                      else t.data.qrcode;
                    else
                      wx.navigateTo({
                        url: "plugin-private://wx393d60d93f70599c/pages/order/index",
                      });
                  })
                  .catch(function (t) {
                    e.setData({ codeValue: null }),
                      s.getTicketConfig(x).then(function (t) {
                        e.setData({ captchaType: t.data.captchaType });
                      }),
                      wx.hideLoading();
                  });
              } else r.showMsg(this.data._t["请选择支付方式"]);
            else r.showMsg(this.data._t["手机号码格式有误"]);
          else r.showMsg(this.data._t["请输入联系电话"]);
        else r.showMsg(this.data._t["请先填写购票信息"]);
      else r.showMsg(this.data._t["请选择参观时段"]);
    else r.showMsg(this.data._t["请选择参观日期"]);
  },
  wechatPay: function (t) {
    var a = this;
    requireMiniProgram()
      .requestPayment(t)
      .then(function (t) {
        if ("requestPayment:ok" == t.errMsg)
          return (
            wx.showLoading({ title: a.data._t["支付处理中"] + "..." }),
            void setTimeout(function () {
              wx.hideLoading(),
                wx.navigateTo({
                  url: "plugin-private://wx393d60d93f70599c/pages/order/index",
                });
            }, 1e3)
          );
      })
      .catch(function (t) {
        "requestPayment:fail cancel" != t.errMsg
          ? "requestPayment:fail cancel" != t.errMsg &&
            "requestPayment:fail" != t.errMsg &&
            wx.showModal({
              title: a.data._t["通知"],
              showCancel: !1,
              content: a.data._t["调起支付失败，请稍后重试"] + "...",
              confirmText: a.data._t["确认"],
            })
          : wx.navigateTo({
              url: "plugin-private://wx393d60d93f70599c/pages/order/index",
            });
      });
  },
  Count: function () {
    if (0 != this.data.count) {
      this.setData({ count: this.data.count - 1 });
      var t = this;
      setTimeout(function () {
        t.Count();
      }, 1e3);
    }
  },
  choosepayMent: function () {
    for (var a = [], e = this.data.ticketTypeList, i = 0; i < e.length; i++)
      for (var s = e[i].groupList, d = 0; d < s.length; d++) a.push(s[d]);
    0 != (a = [].concat(t(a), t(this.data.touristList))).length
      ? "" != this.data.date
        ? "" != this.data.currentTime && null != this.data.currentTime
          ? "" != this.data.ConfirmPhone
            ? r.isMobile(this.data.ConfirmPhone)
              ? this.CreateOrder()
              : r.showMsg(this.data._t["手机号码格式有误"])
            : r.showMsg(this.data._t["请输入联系电话"])
          : r.showMsg(this.data._t["请选择参观时段"])
        : r.showMsg(this.data._t["请选择参观日期"])
      : r.showMsg(this.data._t["请先填写购票信息"]);
  },
  uploadImg: function () {
    var t = this;
    wx.chooseMedia({
      count: 1,
      mediaType: ["image"],
      sourceType: ["album", "camera"],
      camera: "back",
      success: function (a) {
        var e = a.tempFiles[0].tempFilePath;
        t.uploadOcr(e);
      },
    });
  },
  uploadOcr: function (t) {
    var a = this;
    wx.uploadFile({
      url: "".concat(d.Baseurl, "/uploadOcr"),
      filePath: t,
      name: "file",
      header: {
        "Content-Type": "multipart/form-data",
        Authorization: wx.getStorageSync("token"),
      },
      formData: { method: "POST" },
      success: function (t) {
        var e = JSON.parse(t.data);
        500 != e.code
          ? 0 == e.code &&
            a.setData({
              name: e.data.name,
              IdCard: e.data.idNum,
              CardTypeIdx: "0",
            })
          : r.showMsg(e.msg);
      },
    });
  },
  Cancelpay: function () {
    this.setData({ isShowpayMent: !1 });
  },
  changePayMent: function (t) {
    this.setData({ payMent: t.detail.value });
  },
  radioChange: function (t) {
    this.setData({
      productNoIdx: t.detail.value,
      ageMax: this.data.Ticketlist[t.detail.value].ageMax,
      ageMin: this.data.Ticketlist[t.detail.value].ageMin,
      idcardPrefixLimit: this.data.Ticketlist[t.detail.value].idcardPrefixLimit,
    });
  },
  bindPickerChange: function (t) {
    this.setData({
      CardTypeIdx: t.detail.value,
      CardType: this.data.arrayList[t.detail.value].type,
    });
  },
  add: function (a) {
    for (
      var e = [], i = (this.data.ticketTypeList, 0);
      i < this.data.ticketTypeList.length;
      i++
    )
      for (
        var s = this.data.ticketTypeList[i].groupList, d = 0;
        d < s.length;
        d++
      )
        e.push(s[d]);
    (e = [].concat(t(this.data.touristList), t(e))),
      "" != this.data.date
        ? null != this.data.singleBookingLimit &&
          this.data.singleBookingLimit <= e.length
          ? r.showMsg(
              ""
                .concat(this.data._t["最多只能购买"])
                .concat(this.data.singleBookingLimit)
                .concat(this.data._t["人"]),
            )
          : this.setData({
              isShow: !0,
              isSelect: !1,
              ageMax: this.data.Ticketlist[this.data.productNoIdx].ageMax,
              ageMin: this.data.Ticketlist[this.data.productNoIdx].ageMin,
              idcardPrefixLimit:
                this.data.Ticketlist[this.data.productNoIdx].idcardPrefixLimit,
            })
        : r.showMsg(this.data._t["请先选择参观日期"]);
  },
  chooseTime: function (t) {
    var a = t.currentTarget.dataset.idx,
      e = this.data.timeInterval;
    e[a].choose || 0 != e[a].surplusStock || 1 != this.data.isCandidate
      ? e[a].choose
        ? this.setData({ currentTime: JSON.stringify(a), isAgreeCandidate: 0 })
        : r.showMsg(this.data._t["当前时段不可选！"])
      : this.setData({ isShowCandidate: !0, currentTime: JSON.stringify(a) });
  },
  changeDate: function (t) {
    var a = t.currentTarget.dataset.id,
      e = this.data.dateList,
      i = e[a].year + e[a].day;
    this.setData({
      currentTime: null,
      timeInterval: [],
      currentdate: a,
      date: i,
      showDate: "",
    }),
      e[a].stopEntering
        ? r.showMsg(this.data._t["当前日期已停止入馆！"])
        : e[a].stop
          ? r.showMsg(this.data._t["当前日期为闭馆日！"])
          : e[a].reception
            ? r.showMsg(this.data._t["非接待日！"])
            : (this.getTimeSlotsLimit(), this.getProductList());
  },
  chooseDate: function (t) {
    var e,
      i = t.detail.value.split("-"),
      s = i[1] + "-" + i[2],
      d = this.data.dateList,
      o = a(d);
    try {
      for (o.s(); !(e = o.n()).done; ) {
        var n = e.value;
        if (n.day == s && n.stopEntering)
          return void r.showMsg(this.data._t["当前日期已停止入馆！"]);
        if (n.day == s && n.stop)
          return void r.showMsg(this.data._t["当前日期为闭馆日！"]);
        if (n.day == s && n.reception)
          return void r.showMsg(this.data._t["非接待日！"]);
      }
    } catch (t) {
      o.e(t);
    } finally {
      o.f();
    }
    this.setData({
      date: t.detail.value,
      showDate: i[1] + "-" + i[2],
      currentdate: null,
    }),
      this.getTimeSlotsLimit(),
      this.getProductList();
  },
  Alternate: function (t) {
    0 == t.currentTarget.dataset.status
      ? this.setData({
          isShowCandidate: !1,
          isAgreeCandidate: 0,
          currentTime: null,
        })
      : this.setData({ isShowCandidate: !1, isAgreeCandidate: 1 });
  },
  Cancel: function () {
    this.setData({
      isShow: !1,
      currentIdx: null,
      concat_idx: null,
      name: "",
      IdCard: "",
      CardTypeIdx: 0,
      productNoIdx: 0,
      isSelect: !1,
      editType: "Group",
      userList: [],
      userNum: null,
      isEditUser: !1,
    });
  },
  rule: function () {
    this.data.isInstructions || this.Count(),
      this.setData({
        isInstructions: !this.data.isInstructions,
        currentFrame: 0,
      });
  },
  Instructions: function () {
    this.setData({ currentFrame: 1, isInstructions: !0 });
  },
  getName: function (t) {
    this.setData({ name: t.detail.value });
  },
  getIDcard: function (t) {
    this.setData({ IdCard: t.detail.value });
  },
  IDcardBlur: function (t) {
    var a = t.detail.value;
    r.isIdcard(a) || r.showMsg(this.data._t["证件号码格式有误"]);
  },
  getConfirmName: function (t) {
    this.setData({ ConfirmName: t.detail.value });
  },
  getConfirmPhone: function (t) {
    this.setData({ ConfirmPhone: t.detail.value });
  },
  mobielBlur: function () {
    r.isMobile(this.data.ConfirmPhone) ||
      r.showMsg(this.data._t["手机号码格式有误"]);
  },
  calculateTotalAmount: function (t) {
    var e,
      i = 0,
      s = a(t);
    try {
      for (s.s(); !(e = s.n()).done; ) {
        var r = e.value;
        r.price && (i += r.price);
      }
    } catch (t) {
      s.e(t);
    } finally {
      s.f();
    }
    return i;
  },
  addIntegers: function (t, a) {
    return Math.round(t) + Math.round(a);
  },
  isValidCombination: function (t) {
    for (var a = 0, e = 0, i = 0; i < t.length; i++) {
      var s = t[i].customerIdCard,
        r = parseInt(s.substring(6, 10));
      new Date().getFullYear() - r < 17 ? e++ : a++;
    }
    return a === this.data.isAdultCount && e === this.data.isChildCount;
  },
  saveStepUser: function () {
    var e = this,
      i = this.data.currentuserIdx,
      s = this.data.currentIdx,
      d = this.data.ticketTypeList,
      o = this.data.userList,
      n = [];
    if (d.length > 0 && null != s) {
      for (var u = 0; u < d.length; u++)
        for (var c = d[u].groupList, h = 0; h < c.length; h++) n.push(c[h]);
      n = [].concat(t(n), t(this.data.touristList));
    } else {
      for (var l = 0; l < d.length; l++)
        for (var p = d[l].groupList, m = 0; m < p.length; m++) n.push(p[m]);
      for (var g = 0; g < o.length; g++) n.push(o[g]);
      n = [].concat(t(this.data.touristList), t(n));
    }
    if (this.data.isEditUser && s) {
      var I,
        f = a(n);
      try {
        for (f.s(); !(I = f.n()).done; ) {
          var y = I.value;
          if (
            y.customerIdCard == this.data.IdCard.trim() &&
            y.customerIdCard != d[s].groupList[i].customerIdCard
          )
            return void r.showMsg(this.data._t["证件号码不能重复"]);
        }
      } catch (t) {
        f.e(t);
      } finally {
        f.f();
      }
    } else {
      var T,
        C = a(n);
      try {
        for (C.s(); !(T = C.n()).done; ) {
          var x = T.value;
          if (
            x.customerIdCard == this.data.IdCard.trim() &&
            x.customerIdCard !== o[i].customerIdCard
          )
            return void r.showMsg(this.data._t["证件号码不能重复"]);
        }
      } catch (t) {
        C.e(t);
      } finally {
        C.f();
      }
    }
    var v = this.data.userList.map(function (t, a) {
      return a == i
        ? ((t.customerIdCard = e.data.IdCard.trim()),
          (t.customerIdCardType = e.data.CardTypeIdx),
          (t.customerIdCardType = e.data.CardTypeIdx),
          (t.customerName = e.data.name),
          (t.ticketIdx = e.data.productNoIdx),
          t)
        : t;
    });
    if ((console.log(o, "userList"), this.isValidCombination(v)))
      if (d.length > 0 && null != s)
        (d[s].groupList[i].customerName = this.data.name),
          (d[s].groupList[i].customerIdCardType = this.data.CardTypeIdx),
          (d[s].groupList[i].customerIdCard = this.data.IdCard.trim()),
          this.setData({
            ticketTypeList: d,
            userList: [],
            isShow: !1,
            isEditUser: !1,
            name: "",
            IdCard: "",
            currentIdx: null,
          });
      else {
        if (
          (this.setData({
            userList: o,
            isEditUser: !1,
            name: "",
            IdCard: "",
            currentIdx: null,
          }),
          o.length < this.data.userNum)
        )
          return;
        this.nextStepUser();
      }
    else r.showMsg(this.data._t["请确定本人及儿童信息是否正确"]);
  },
  saveStepUserS: function (e) {
    var i = this,
      s = this.data.currentuserIdx,
      d = this.data.currentIdx,
      o = this.data.ticketTypeList,
      n = [];
    if (o.length > 0 && null != d) {
      for (var u = this.data.ticketTypeList, c = 0; c < u.length; c++)
        for (var h = u[c].groupList, l = 0; l < h.length; l++) n.push(h[l]);
      n = [].concat(t(n), t(this.data.touristList));
    } else {
      for (var p = 0; p < e.length; p++) n.push(e[p]);
      n = [].concat(t(this.data.touristList), t(n));
    }
    if (this.data.isEditUser && d) {
      var m,
        g = a(n);
      try {
        for (g.s(); !(m = g.n()).done; ) {
          var I = m.value;
          if (
            I.customerIdCard == this.data.IdCard.trim() &&
            I.customerIdCard != o[d].groupList[s].customerIdCard
          )
            return void r.showMsg(this.data._t["证件号码不能重复"]);
        }
      } catch (t) {
        g.e(t);
      } finally {
        g.f();
      }
    } else {
      var f,
        y = a(n);
      try {
        for (y.s(); !(f = y.n()).done; ) {
          var T = f.value;
          if (
            T.customerIdCard == this.data.IdCard.trim() &&
            T.customerIdCard !== e[s].customerIdCard
          )
            return void r.showMsg(this.data._t["证件号码不能重复"]);
        }
      } catch (t) {
        y.e(t);
      } finally {
        y.f();
      }
    }
    e.map(function (t, a) {
      return a == s
        ? ((t.customerIdCard = i.data.IdCard.trim()),
          (t.customerIdCardType = i.data.CardTypeIdx),
          (t.customerIdCardType = i.data.CardTypeIdx),
          (t.customerName = i.data.name),
          (t.ticketIdx = i.data.productNoIdx),
          t)
        : t;
    });
    if ((console.log(e, "userList"), this.isValidCombination(e)))
      if (o.length > 0 && null != d)
        (o[d].groupList[s].customerName = this.data.name),
          (o[d].groupList[s].customerIdCardType = this.data.CardTypeIdx),
          (o[d].groupList[s].customerIdCard = this.data.IdCard.trim()),
          this.setData({
            ticketTypeList: o,
            userList: [],
            isShow: !1,
            isEditUser: !1,
            name: "",
            IdCard: "",
            currentIdx: null,
          });
      else {
        if (
          (this.setData({
            userList: e,
            isEditUser: !1,
            name: "",
            IdCard: "",
            currentIdx: null,
          }),
          e.length < this.data.userNum)
        )
          return;
        this.nextStepUser();
      }
    else r.showMsg(this.data._t["请确定本人及儿童信息是否正确"]);
  },
  setTourist: function (t) {
    var a = this,
      e = t.currentTarget.dataset.idx;
    if (this.data.userList.length === this.data.userNum) {
      var i = this.data.arrayList.findIndex(function (t) {
        return t.type == a.data.userList[e].customerIdCardType;
      });
      this.setData({
        CardTypeIdx: i + "",
        name: this.data.userList[e].customerName,
        IdCard: this.data.userList[e].customerIdCard,
        productNoIdx: this.data.userList[e].ticketIdx,
        isEditUser: !0,
        currentuserIdx: e,
        editType: "Group",
      });
    }
  },
  nextStepUser: function () {
    var e = this;
    if (
      this.data.isEditUser ||
      this.data.userNum != this.data.userList.length
    ) {
      for (
        var i = [],
          s = this.data.currentuserIdx,
          d = this.data.currentIdx,
          o = this.data.ticketTypeList,
          n = 0;
        n < this.data.ticketTypeList.length;
        n++
      )
        for (
          var u = this.data.ticketTypeList[n].groupList, c = 0;
          c < u.length;
          c++
        )
          i.push(u[c]);
      if (
        ((i = [].concat(t(i), t(this.data.touristList), t(this.data.userList))),
        !this.data.isEditUser &&
          this.data.userNum !== this.data.userList.length)
      ) {
        for (var h = 0; h < this.data.ticketTypeList.length; h++)
          for (
            var l = this.data.ticketTypeList[h].groupList, p = 0;
            p < l.length;
            p++
          )
            i.push(l[p]);
        i = [].concat(t(i), t(this.data.userList));
      }
      if (
        null != this.data.singleBookingLimit &&
        this.data.singleBookingLimit <= i.length
      )
        r.showMsg(
          ""
            .concat(this.data._t["抱歉一次最多只能添加"])
            .concat(this.data.singleBookingLimit)
            .concat(this.data._t["用户"]),
        );
      else if ("" != this.data.name)
        if (-1 != this.data.CardTypeIdx)
          if ("" != this.data.IdCard)
            if (null != this.data.productNoIdx) {
              if (
                0 == this.data.CardTypeIdx &&
                null != this.data.idcardPrefixLimit
              ) {
                var m = this.data.idcardPrefixLimit.split(",");
                if (!r.isIdcardPrefix(this.data.IdCard.trim(), m))
                  return void r.showMsg(
                    this.data._t["抱歉，当前证件号码不能购买该产品"],
                  );
              }
              if (
                0 == this.data.CardTypeIdx &&
                null != this.data.ageMax &&
                r.getAge(this.data.IdCard.trim()) > this.data.ageMax
              )
                r.showMsg(this.data._t["抱歉，年龄不符合此产品购买条件"]);
              else if (
                0 == this.data.CardTypeIdx &&
                null != this.data.ageMin &&
                r.getAge(this.data.IdCard.trim()) < this.data.ageMin
              )
                r.showMsg(this.data._t["抱歉，年龄不符合此产品购买条件"]);
              else {
                if (null != this.data.currentIdx && this.data.isEditUser) {
                  var g,
                    I = a(i);
                  try {
                    for (I.s(); !(g = I.n()).done; ) {
                      var f = g.value;
                      if (
                        (f.customerIdCard == this.data.IdCard &&
                          f.customerIdCard !==
                            i[this.data.currentIdx].customerIdCard) ||
                        (f.customerIdCard == this.data.IdCard.trim() &&
                          f.customerIdCard != o[d].groupList[s].customerIdCard)
                      )
                        return void r.showMsg(this.data._t["证件号码不能重复"]);
                    }
                  } catch (t) {
                    I.e(t);
                  } finally {
                    I.f();
                  }
                }
                if (null == this.data.currentIdx && !this.data.isEditUser) {
                  var y,
                    T = a(i);
                  try {
                    for (T.s(); !(y = T.n()).done; ) {
                      if (y.value.customerIdCard == this.data.IdCard.trim())
                        return void r.showMsg(this.data._t["证件号码不能重复"]);
                    }
                  } catch (t) {
                    T.e(t);
                  } finally {
                    T.f();
                  }
                }
                if (this.data.isEditUser)
                  return (
                    (o[d].groupList[s].customerName = this.data.name),
                    (o[d].groupList[s].customerIdCardType =
                      this.data.arrayList[this.data.CardTypeIdx].type),
                    (o[d].groupList[s].customerIdCard =
                      this.data.IdCard.trim()),
                    void this.setData({
                      ticketTypeList: o,
                      isShow: !1,
                      isEditUser: !1,
                      currentIdx: null,
                      currentuserIdx: null,
                      userNum: null,
                      isSelect: !1,
                      editType: "Group",
                    })
                  );
                var C = this.data.userList;
                C.push({
                  nums: 1,
                  customerName: this.data.name,
                  customerIdCard: this.data.IdCard.trim(),
                  customerIdCardType:
                    this.data.arrayList[this.data.CardTypeIdx].type,
                  abbreviation:
                    this.data.Ticketlist[this.data.productNoIdx].abbreviation,
                  productNameEn:
                    this.data.Ticketlist[this.data.productNoIdx].productNameEn,
                  productNo:
                    this.data.Ticketlist[this.data.productNoIdx].productNo,
                  ticketIdx: this.data.productNoIdx,
                });
                var x = this.data.totalPrice;
                if (
                  ((x = (
                    parseFloat(x) +
                    parseFloat(
                      this.data.Ticketlist[this.data.productNoIdx].price,
                    )
                  ).toFixed(2)),
                  this.setData({
                    userList: C,
                    editType: "Group",
                    currentuserIdx: null,
                  }),
                  C.length == this.data.userNum)
                ) {
                  var v = this.data.touristList,
                    L = this.data.userList,
                    N = this.isValidCombination(this.data.userList),
                    w = this.data.arrayList.findIndex(function (t) {
                      return t.type == e.data.userList[0].customerIdCardType;
                    });
                  if (!N)
                    return (
                      r.showMsg(this.data._t["请确定本人及儿童信息是否正确"]),
                      void this.setData({
                        name: this.data.userList[0].customerName,
                        IdCard: this.data.userList[0].customerIdCard,
                        CardTypeIdx: w,
                        currentuserIdx: 0,
                        editType: "Group",
                        isEditUser: !0,
                      })
                    );
                  var k = this.data.ticketTypeList;
                  k.push({
                    nums: 1,
                    abbreviation:
                      this.data.Ticketlist[this.data.productNoIdx].abbreviation,
                    productNameEn:
                      this.data.Ticketlist[this.data.productNoIdx]
                        .productNameEn,
                    productNo:
                      this.data.Ticketlist[this.data.productNoIdx].productNo,
                    ticketIdx: this.data.productNoIdx,
                    price: this.data.Ticketlist[this.data.productNoIdx].price,
                    groupList: L,
                  });
                  var M = this.calculateTotalAmount(k),
                    D = this.calculateTotalAmount(v);
                  this.setData({
                    ticketTypeList: k,
                    totalPrice: parseFloat(M + D).toFixed(2),
                    currentIdx: null,
                    currentuserIdx: null,
                    userList: [],
                    name: "",
                    IdCard: "",
                    CardTypeIdx: "0",
                    concat_idx: null,
                    productNoIdx: 0,
                    isSelect: !1,
                    userNum: 1,
                    isShow: !1,
                    editType: "Group",
                  });
                }
                this.setData({
                  name: "",
                  IdCard: "",
                  CardTypeIdx: "0",
                  editType: "Group",
                });
              }
            } else r.showMsg(this.data._t["请选择门票"]);
          else r.showMsg(this.data._t["证件号码不能为空"]);
        else r.showMsg(this.data._t["请选择证件类型"]);
      else r.showMsg(this.data._t["姓名不能为空"]);
    } else {
      var _ = this.data.touristList,
        S = this.data.userList;
      if (!this.isValidCombination(this.data.userList))
        return void r.showMsg(this.data._t["请确定本人及儿童信息是否正确"]);
      var P = this.data.ticketTypeList;
      P.push({
        nums: 1,
        abbreviation: this.data.Ticketlist[this.data.productNoIdx].abbreviation,
        productNameEn:
          this.data.Ticketlist[this.data.productNoIdx].productNameEn,
        productNo: this.data.Ticketlist[this.data.productNoIdx].productNo,
        ticketIdx: this.data.productNoIdx,
        price: this.data.Ticketlist[this.data.productNoIdx].price,
        groupList: S,
      });
      var b = this.calculateTotalAmount(P),
        E = this.calculateTotalAmount(_);
      this.setData({
        ticketTypeList: P,
        totalPrice: parseFloat(b + E).toFixed(2),
        currentIdx: null,
        currentuserIdx: null,
        userList: [],
        name: "",
        IdCard: "",
        CardTypeIdx: 0,
        concat_idx: null,
        productNoIdx: 0,
        isSelect: !1,
        userNum: 1,
        isShow: !1,
        editType: "Group",
      });
    }
  },
  confirmTourist: function () {
    for (
      var e = [], i = this.data.ticketTypeList, s = 0;
      s < this.data.ticketTypeList.length;
      s++
    )
      for (
        var d = this.data.ticketTypeList[s].groupList, o = 0;
        o < d.length;
        o++
      )
        e.push(d[o]);
    if (((e = [].concat(t(this.data.touristList), t(e))), "" != this.data.name))
      if (-1 != this.data.CardTypeIdx)
        if ("" != this.data.IdCard.trim())
          if (null != this.data.productNoIdx) {
            if (
              0 == this.data.CardTypeIdx &&
              null != this.data.idcardPrefixLimit
            ) {
              var n = this.data.idcardPrefixLimit.split(",");
              if (!r.isIdcardPrefix(this.data.IdCard.trim(), n))
                return void r.showMsg(
                  this.data._t["抱歉，当前证件号码不能购买该产品"],
                );
            }
            if (
              0 == this.data.CardTypeIdx &&
              null != this.data.ageMax &&
              r.getAge(this.data.IdCard.trim()) > this.data.ageMax
            )
              r.showMsg(this.data._t["抱歉，年龄不符合此产品购买条件"]);
            else if (
              0 == this.data.CardTypeIdx &&
              null != this.data.ageMin &&
              r.getAge(this.data.IdCard.trim()) < this.data.ageMin
            )
              r.showMsg(this.data._t["请先填写购票信息"]);
            else {
              if (null != this.data.currentIdx) {
                var u,
                  c = a(e);
                try {
                  for (c.s(); !(u = c.n()).done; ) {
                    var h = u.value;
                    if (
                      h.customerIdCard == this.data.IdCard.trim() &&
                      h.customerIdCard != e[this.data.currentIdx].customerIdCard
                    )
                      return void r.showMsg(this.data._t["请先填写购票信息"]);
                  }
                } catch (t) {
                  c.e(t);
                } finally {
                  c.f();
                }
              }
              if (null == this.data.currentIdx) {
                var l,
                  p = a(e);
                try {
                  for (p.s(); !(l = p.n()).done; ) {
                    if (l.value.customerIdCard == this.data.IdCard.trim())
                      return void r.showMsg(this.data._t["请先填写购票信息"]);
                  }
                } catch (t) {
                  p.e(t);
                } finally {
                  p.f();
                }
              }
              var m = this.calculateTotalAmount(i);
              if (null != this.data.currentIdx) {
                var g = this.data.touristList;
                (g[this.data.currentIdx].customerName = this.data.name),
                  (g[this.data.currentIdx].customerIdCardType =
                    this.data.arrayList[this.data.CardTypeIdx].type),
                  (g[this.data.currentIdx].customerIdCard =
                    this.data.IdCard.trim()),
                  (g[this.data.currentIdx].abbreviation =
                    this.data.Ticketlist[this.data.productNoIdx].abbreviation),
                  (g[this.data.currentIdx].productNameEn =
                    this.data.Ticketlist[this.data.productNoIdx].productNameEn),
                  (g[this.data.currentIdx].productNo =
                    this.data.Ticketlist[this.data.productNoIdx].productNo),
                  (g[this.data.currentIdx].price =
                    this.data.Ticketlist[this.data.productNoIdx].price),
                  (g[this.data.currentIdx].ticketIdx = this.data.productNoIdx);
                var I,
                  f = 0,
                  y = a(g);
                try {
                  for (y.s(); !(I = y.n()).done; ) {
                    var T = I.value;
                    f = (parseFloat(f) + parseFloat(T.price)).toFixed(2);
                  }
                } catch (t) {
                  y.e(t);
                } finally {
                  y.f();
                }
                return (
                  (f = (parseFloat(m) + parseFloat(f)).toFixed(2)),
                  void this.setData({
                    touristList: g,
                    currentIdx: null,
                    isShow: !1,
                    name: "",
                    IdCard: "",
                    CardTypeIdx: 0,
                    concat_idx: null,
                    productNoIdx: 0,
                    totalPrice: f,
                    isSelect: !1,
                    userNum: 1,
                    currentuserIdx: null,
                    editType: "Group",
                  })
                );
              }
              var C = this.data.touristList;
              C.push({
                nums: 1,
                customerName: this.data.name,
                customerIdCard: this.data.IdCard.trim(),
                customerIdCardType:
                  this.data.arrayList[this.data.CardTypeIdx].type,
                abbreviation:
                  this.data.Ticketlist[this.data.productNoIdx].abbreviation,
                productNameEn:
                  this.data.Ticketlist[this.data.productNoIdx].productNameEn,
                productNo:
                  this.data.Ticketlist[this.data.productNoIdx].productNo,
                ticketIdx: this.data.productNoIdx,
                price: this.data.Ticketlist[this.data.productNoIdx].price,
              });
              var x,
                v = this.data.touristList,
                L = this.calculateTotalAmount(v);
              (x = (parseFloat(m) + parseFloat(L)).toFixed(2)),
                this.setData({
                  touristList: C,
                  name: "",
                  IdCard: "",
                  CardTypeIdx: 0,
                  productNoIdx: 0,
                  isShow: !1,
                  concat_idx: null,
                  totalPrice: x,
                  currentuserIdx: null,
                  isSelect: !1,
                  editType: "Group",
                });
            }
          } else r.showMsg(this.data._t["请选择门票"]);
        else r.showMsg(this.data._t["证件号码不能为空"]);
      else r.showMsg(this.data._t["请选择证件类型"]);
    else r.showMsg(this.data._t["姓名不能为空"]);
  },
  delTourist: function (t) {
    var a = t.currentTarget.dataset.idx,
      e = t.currentTarget.dataset.type,
      i = this;
    console.log(5555),
      wx.showModal({
        title: i.data._t["提示"],
        content: i.data._t["是否确认删除"],
        confirmText: i.data._t["确定"],
        cancelText: i.data._t["取消"],
        success: function (t) {
          if (t.confirm) {
            if ("user" == e) {
              var s = i.data.userList;
              return (
                s.splice(a, 1),
                this.isEditUser ||
                  i.setData({
                    name: "",
                    IdCard: "",
                    CardTypeIdx: "0",
                    isEditUser: !1,
                    currentuserIdx: null,
                  }),
                void i.setData({ userList: s })
              );
            }
            if ("Group" == e) {
              var r = i.data.ticketTypeList,
                d = i.data.totalPrice;
              return (
                (d = (parseFloat(d) - parseFloat(r[a].price)).toFixed(2)),
                r.splice(a, 1),
                void i.setData({ ticketTypeList: r, totalPrice: d })
              );
            }
            var o = i.data.touristList,
              n = i.data.totalPrice;
            (n = (parseFloat(n) - parseFloat(o[a].price)).toFixed(2)),
              o.splice(a, 1),
              i.setData({ touristList: o, totalPrice: n });
          }
        },
      });
  },
  getselectedCard: function (t, a) {},
  editTourist: function (t) {
    var a = this,
      e = t.currentTarget.dataset.idx,
      i = t.currentTarget.dataset.idxs,
      s = t.currentTarget.dataset.edittype,
      r = (t.currentTarget.dataset.problemitem, t.currentTarget.dataset.item);
    if ("Group" == s) {
      var d = this.data.arrayList.findIndex(function (t) {
        return (
          t.type == a.data.ticketTypeList[e].groupList[i].customerIdCardType ||
          0
        );
      });
      this.setData({
        isShow: !0,
        isEditUser: !0,
        currentIdx: e,
        currentuserIdx: i,
        userNum: r.groupList.length,
        userList: r.groupList,
        isSelect: !0,
        editType: "Group",
        CardTypeIdx: d,
        name: this.data.ticketTypeList[e].groupList[i].customerName,
        IdCard: this.data.ticketTypeList[e].groupList[i].customerIdCard,
        productNoIdx: this.data.ticketTypeList[e].ticketIdx,
      });
    } else {
      var o = this.data.arrayList.findIndex(function (t) {
        return t.type == a.data.touristList[e].customerIdCardType;
      });
      this.setData({
        editType: "other",
        currentIdx: e,
        isSelect: !0,
        userNum: 1,
        isShow: !0,
        CardTypeIdx: 0 == o ? "0" : o,
        name: this.data.touristList[e].customerName,
        IdCard: this.data.touristList[e].customerIdCard,
        productNoIdx: this.data.touristList[e].ticketIdx,
      });
    }
  },
  catchtouchmove: function () {},
  toPage: function () {
    wx.navigateTo({
      url: "plugin-private://wx393d60d93f70599c/pages/Rule/index?orderType=0&teamType=0",
    });
  },
  onPullDownRefresh: function () {
    this.onLoad();
  },
  onShareAppMessage: function () {},
});
